﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Services.Description;
using BusinessLayer;
using Position = JuniorChatBox.Models.Position;

namespace JuniorChatBox.Controllers
{
    public class ChatBoxController : Controller
    {
        //
        // GET: /ChatBox/

        public ActionResult Index()
        {
            return View(ServiceFactory.CreateChatBoxService().GetCurrentUsers());
        }

        [HttpPost]
        public ActionResult LogIn(string name,Position position)
        {
            return Json(ServiceFactory.CreateChatBoxService().Login(name,new BusinessLayer.Position(position.Latitude,position.Longitude)));
        }

        /*[HttpPost]
        public ActionResult LogIn(string name,Position position)
        {
            return Json(ServiceFactory.CreateChatBoxService().Login(name, position));
        }*/

        [HttpPost]
        public ActionResult Register(string name, string nickname, string iconUrl)
        {
            //normaal position in parameter meegeven maar geeft nog error clientside (kan dat object nog niet meesturen)
            //voorlopig zo oplossen:
            BusinessLayer.Position position = new BusinessLayer.Position(50.8137881, 3.4914213000000003);
            return Json(ServiceFactory.CreateChatBoxService().Register(name, nickname, iconUrl,position));
        }

        [HttpPost]
        public ActionResult SendMessage(int id, string message)
        {
            return Json(ServiceFactory.CreateChatBoxService().SendMessage(id, message));
        }

        [HttpGet]
        public ActionResult GetList()
        {
            return Json(ServiceFactory.CreateChatBoxService().GetCurrentUsers(),JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public ActionResult GetLastMessages(int id)
        {
            return Json(ServiceFactory.CreateChatBoxService().GetLastMessages(id), JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        public ActionResult GetImages()
        {
            return Json(ServiceFactory.CreateChatBoxService().GetImages(), JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public String clearList()
        {
            ServiceFactory.CreateChatBoxService().ClearList();
            return "ok";

        } 
        public ViewResult GoToRegister()
        {
            return View("RegisterPage");
        }

        public ViewResult About()
        {
            return View("About", ServiceFactory.CreateChatBoxService().GetCurrentUsers());
        }
    }
}
